package com.itheima.mall.web.sms;

import com.itheima.mall.dto.ListDtoPage;
import com.itheima.mall.pojo.sms.SmsFlashPromotionProductRelation;
import com.itheima.mall.vo.PageResult;
import com.itheima.mall.vo.R;
import com.itheima.mall.service.sms.SmsFlashPromotionProductRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashProductRelation")
public class SmsFlashPromotionProductRelationController {
    @Autowired
    SmsFlashPromotionProductRelationService relation;

    /**
     * 批量商品关联
     * @param relations
     * @return
     */
    @PostMapping("/create")
    public R<String> addRelation(@RequestBody List<SmsFlashPromotionProductRelation> relations){
        relation.addRelation(relations);
        return R.succeed(null,"批量关联成功");
    }

    /**
     * 删除商品关联
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public R<String> deleteRelation(@PathVariable Long id){
        relation.deleteRelation(id);
        return R.succeed(null,"删除成功");
    }
    /**
     * 分页显示关联信息
     */
    @GetMapping("list")
    public R getList(@RequestParam(value = "flashPromotionId",required = false)Integer flashPromotionId,
                                     @RequestParam("flashPromotionSessionId")Integer flashPromotionSessionId,
                                     @RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        PageResult list = relation.getList(flashPromotionId, flashPromotionSessionId, pageNum, pageSize);
        return R.succeed(list,"查询成功");
    }
    @PostMapping("update/{id}")
    public R updateRelation(@RequestBody SmsFlashPromotionProductRelation relation1,@PathVariable Integer id){
        relation.updateRelation(relation1);
        return R.succeed(null,"更新成功");
    }

    /**
     * 获取详细信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R getRelation(@PathVariable Integer id){
        SmsFlashPromotionProductRelation relation = this.relation.getRelation(id);
        return R.succeed(relation,"查询成功");
    }
}
